package spring_annotation.condition;

import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;
import spring_annotation.pojo.Success;

public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {
    @Override
    public void registerBeanDefinitions(AnnotationMetadata annotationMetadata,
                                        BeanDefinitionRegistry beanDefinitionRegistry) {
        boolean definition01 = beanDefinitionRegistry.containsBeanDefinition("spring_annotation.pojo.Color");
        boolean definition02 = beanDefinitionRegistry.containsBeanDefinition("spring_annotation.pojo.Shape");
        if(definition01 && definition02){
            RootBeanDefinition beanDefinition = new RootBeanDefinition(Success.class);
            beanDefinitionRegistry.registerBeanDefinition("success", beanDefinition);
        }
    }
}
